<template>
  <p-card :bordered="false">
    <!-- 查询区域 -->
    <!-- 查询区域 -->

    <div class="table-page-search-wrapper">
      <p-form layout="inline" @keyup.enter.native="searchQuery">
        <p-row :gutter="24">
          <p-col :xl="6" :lg="7" :md="8" :sm="24">
            <p-form-item label="条码生成编码">
              <p-select v-model="active" default-value="请选择">
                <p-select-option value="0">请选择</p-select-option>
                <p-select-option
                  @click="QueryList(value)"
                  :value="value.produceNo"
                  :key="value.id"
                  v-for="value in mes_filed_type"
                  >{{ value.produceNo }}</p-select-option
                >
              </p-select>
            </p-form-item>
          </p-col>
          <p-col :xl="8" :lg="7" :md="8" :sm="24">
            <p-form-item label="标签模板编码">
              <p-select v-model="NolistActive" default-value="请选择">
                <p-select-option value="0">请选择</p-select-option>
                <p-select-option
                  @click="QueryData(value)"
                  :value="value.labelTemplateNo + ' ' + value.labelTemplateName"
                  :key="value.id"
                  v-for="value in queryParam"
                  >{{
                    value.labelTemplateNo + " " + value.labelTemplateName
                  }}</p-select-option
                >
              </p-select>
            </p-form-item>
          </p-col>
          <template>
            <p-col :xl="6" :lg="7" :md="8" :sm="24">
              <p-form-item label="标签模板名称">
                <p-input
                  readonly
                  placeholder="产品名称"
                  disabled
                  v-model="queryList.labelTemplateName"
                ></p-input>
              </p-form-item>
            </p-col>
          </template>
          <template>
            <p-col :xl="6" :lg="7" :md="8" :sm="24">
              <p-form-item label="数量">
                <p-input
                  readonly
                  placeholder="数量"
                  disabled
                  v-model="listLength"
                ></p-input>
              </p-form-item>
            </p-col>
          </template>
          <template>
            <p-col :xl="6" :lg="7" :md="8" :sm="24">
              <p-form-item label="打印份数">
                <p-input
                  readonly
                  placeholder="打印份数"
                  v-model="NumberParinted"
                ></p-input>
              </p-form-item>
            </p-col>
          </template>

          <template>
            <p-col :xl="6" :lg="7" :md="8" :sm="24">
              <p-form-item label="补印份数">
                <p-input
                  placeholder="请输入补印数量"
                  v-model="supplementParinted"
                ></p-input>
              </p-form-item>
            </p-col>
          </template>
          <p-col :xl="6" :lg="7" :md="8" :sm="24" class="table-operator">
            <p-button
              type="primary"
              :span="6"
              icon="printer"
              @click="handleAlert"
              >打印</p-button
            >
            <p-button
              type="primary"
              :span="6"
              icon="printer"
              @click="handleClick"
              >试打</p-button
            >
            <p-button
              type="primary"
              :span="6"
              @click="searchQuery"
              icon="search"
              >搜索</p-button
            >
            <p-button type="primary" :span="6" icon="printer" @click="myAddHtml"
              >补印</p-button
            >
          </p-col>
        </p-row>
      </p-form>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>

        <span style="float: right">
          <p-divider type="vertical" />
          <a @click="loadData()"> <p-icon type="sync" />刷新 </a>
          <p-divider type="vertical" />
          <p-popover
            title="自定义列"
            trigger="click"
            placement="leftBottom"
            :overlay-style="getWidth"
          >
            <template slot="content">
              <p-checkbox-group
                @change="onColSettingsChange"
                v-model="settingColumns"
                :defaultValue="settingColumns"
              >
                <p-row>
                  <template v-for="(item, index) in defColumns">
                    <template
                      v-if="
                        item.key != 'rowIndex' && item.dataIndex != 'action'
                      "
                    >
                      <p-col :span="12" :key="index">
                        <p-checkbox :value="item.dataIndex">{{
                          item.title
                        }}</p-checkbox>
                      </p-col>
                    </template>
                  </template>
                </p-row>
              </p-checkbox-group>
            </template>
            <a> <p-icon type="setting" />自定义列 </a>
          </p-popover>
        </span>
      </div>

      <p-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :scroll="tableScroll"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{
          selectedRowKeys: selectedRowKeys,
          onChange: onSelectChange,
          type: 'radio',
        }"
        @change="handleTableChange"
      >
        <template slot="status" slot-scope="text, record">
          <f-switch
            v-model="record.status"
            field="record"
            :disabled="true"
            dictCode="mes_status2"
            size="small"
          />
        </template>

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>

        <template slot="labelTemplateLength" slot-scope="text">
          {{ labelTemplateLengthKeys[text] }}
        </template>

        <template slot="labelType" slot-scope="text">
          {{ labelTypeKeys[text] }}
        </template>

        <template slot="labelColor" slot-scope="text">
          {{ labelColorKeys[text] }}
        </template>

        <template slot="labelColor" slot-scope="text">
          {{ labelColorKeys[text] }}
        </template>

        <template slot="ribbonsType" slot-scope="text">
          {{ ribbonsTypeKeys[text] }}
        </template>

        <template slot="printerType" slot-scope="text">
          {{ printerTypeKeys[text] }}
        </template>

        <template slot="containSn" slot-scope="text">
          {{ containSnKeys[text] }}
        </template>

        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic"
            >无此图片</span
          >
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt="图片不存在"
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic"
            >无此文件</span
          >
          <p-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)"
            >下载</p-button
          >
        </template>
      </p-table>
    </div>

    <p-tabs defaultActiveKey="1">
      <p-tab-pane tab="条码明细" key="1">
        <mes-bc-supper-field-list :mainId="mainId" @fromChild="getChild" />
      </p-tab-pane>
    </p-tabs>

    <!-- <mesBcField-modal ref="modalForm" :EnhanceJS="EnhanceJS" @ok="modalFormOk"></mesBcField-modal> -->
    <!-- 弹出窗 -->
    <!-- <Fx-compontens-modal
      @ok="modalFormOk"
      ref="modalCompon"
      :getList="queryInfo"
      :title="title"
      :dictOptions="dictOptions"
    ></Fx-compontens-modal> -->

    <p-modal
      id="alertText"
      title="Title"
      :visible="visible"
      :confirm-loading="confirmLoading"
      @ok="handleOk"
      @cancel="handleCancel"
      >{{ $AlertTxt }}</p-modal
    >
  </p-card>
</template>

<script>
import { JeecgListMixin } from "@/mixins/JeecgListMixin";
import { api } from "@/api/manage";
import JSuperQuery from "@/components/jeecg/JSuperQuery.vue";
import { filterObj } from "@/utils/util";
import MesBcFieldModal from "./modules/MesBcFieldModal";
import Vue from "vue";
import MesBcSupperFieldList from "./MesBcSupperFieldList";
import { mapState } from "vuex";
import moment from "moment";
import { ajaxGetDictItems } from "@/api/api";
import {
  initDictOptions,
  filterMultiDictText,
} from "@/components/dict/JDictSelectUtil";
import ButtonExpHandler from "@/components/jeecgbiz/modules/ButtonExpHandler";
import {
  postAction,
  getAction,
  deleteAction,
  postActionBasic,
} from "@/api/manage";
import FxCompontensModal from "@/components/jeecgbiz/FxCompontensModal";

//高级查询modal需要参数
const superQueryFieldList = [
  {
    value: "filedCode",
    text: "字段编码",
    type: "String",
  },
  {
    value: "filedName",
    text: "字段名称",
    type: "String",
  },
  {
    value: "filedType",
    text: "字段属性",
    type: "select",
    dictCode: "mes_filed_type",
  },
  {
    value: "filedLength",
    text: "字段位数",
    type: "int",
  },
  {
    value: "barcodeBinary",
    text: "进制",
    type: "select",
    dictCode: "mes_barcode_binary",
  },
  {
    value: "filedCharacter",
    text: "字段字符",
    type: "String",
  },
  {
    value: "barcodeSource",
    text: "来源",
    type: "select",
    dictCode: "mes_barcode_source",
  },
  {
    value: "filedSample",
    text: "字段示例",
    type: "String",
  },
  {
    value: "filedExplain",
    text: "字段说明",
    type: "String",
  },
  {
    value: "status",
    text: "状态",
    type: "select",
    dictCode: "mes_status2",
  },
  {
    value: "remark",
    text: "备注",
    type: "string",
  },
  {
    value: "createBy",
    text: "创建人",
    type: "string",
  },
  {
    value: "createTime",
    text: "创建日期",
    type: "Date",
  },
  {
    value: "updateBy",
    text: "更新人",
    type: "string",
  },
  {
    value: "updateTime",
    text: "更新日期",
    type: "Date",
  },
];

export default {
  name: "MesBcFieldList",
  mixins: [JeecgListMixin],
  components: {
    JSuperQuery,
    MesBcSupperFieldList,
    FxCompontensModal,
    MesBcFieldModal,
  },
  data() {
    return {
      selectionRows: {},
      labelTemplateLengthKeys: {},
      labelTypeKeys: {},
      labelColorKeys: {},
      ribbonsTypeKeys: {},
      printerTypeKeys: {},
      containSnKeys: {},
      validatorRules: {
        filedCode: { rules: [{ required: true, message: "请输入字段编码!" }] },
        filedName: { rules: [{ required: false, message: "请输入字段名称!" }] },
        filedType: { rules: [{ required: false, message: "请输入字段属性!" }] },
        filedLength: {
          rules: [{ required: true, message: "请输入字段位数!" }],
        },
        barcodeBinary: {},
        filedCharacter: {
          rules: [{ required: true, message: "请输入字段字符!" }],
        },
        barcodeSource: { rules: [{ required: true, message: "请输入来源!" }] },
        filedSample: {
          rules: [{ required: true, message: "请输入字段示例!" }],
        },
        filedExplain: {},
        status: {},
        remark: {},
      },
      supplementParinted: 0,
      NumberParinted: "",
      active: "请选择",
      NolistActive: "请选择",
      mes_filed_type: [],
      listLength: "",
      mainId: "",
      AlertTxt: "",
      queryParam: {},
      changeData: {},
      fieldList: superQueryFieldList,
      superQueryFlag: false,
      loading: false,
      superQueryParams: "",
      description: "关键字段信息管理页面",
      EnhanceJS: {},
      plainOptions: [],
      cgButtonLinkList: [],
      dataSource: [],
      cgButtonList: [],
      title: "", //存表名
      groupTag: [],
      queryInfo: [],
      queryList: "",
      visible: false,
      code: "",
      // 表头
      columns: [],
      //列设置
      settingColumns: [],
      //列定义
      defColumns: [
        {
          title: "序号",
          align: "center",
          dataIndex: "number",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          },
        },
        {
          title: "标签模板编号",
          align: "center",
          dataIndex: "labelTemplateNo",
        },
        {
          title: "标签模板名称",
          align: "center",
          dataIndex: "labelTemplateName",
        },
        {
          title: "标签模板描述",
          align: "center",
          dataIndex: "mexplain",
        },
        {
          title: "标签模板尺寸",
          align: "center",
          dataIndex: "labelTemplateLength",
          scopedSlots: { customRender: "labelTemplateLength" },
        },
        {
          title: "标签类型",
          align: "center",
          dataIndex: "labelType",
          scopedSlots: { customRender: "labelType" },
        },
        {
          title: "责任部门",
          align: "center",
          dataIndex: "department",
        },
        {
          title: "标签纸颜色",
          align: "center",
          dataIndex: "labelColor",
          scopedSlots: { customRender: "labelColor" },
        },
        {
          title: "碳带型号",
          align: "center",
          dataIndex: "ribbonsType",
          scopedSlots: { customRender: "ribbonsType" },
        },
        {
          title: "打印机型号",
          align: "center",
          dataIndex: "printerType",
          scopedSlots: { customRender: "printerType" },
        },
        {
          title: "是否包含流水号",
          align: "center",
          dataIndex: "containSn",
          scopedSlots: { customRender: "containSn" },
        },

        // {
        //   title: "已打印份数",
        //   align: "center",
        //   dataIndex: "overPrinted",
        // },
      ],
      url: {
        NoList: "/mes-code/mesBcProduce/getBcProNoList",
        list: "/mes-code/mesBcTemplate/list",
        delete: "/mes-code/mesBcField/delete",
        deleteBatch: "/mes-code/mesBcField/deleteBatch",
        exportXlsUrl: "/mes-code/mesBcField/exportXls",
        importExcelUrl: "/mes-code/mesBcField/importExcel",
        getColumns: "/mes-code/online/cgform/api/getColumns/",
        buttonAction: "/mes-code/online/cgform/api/doButton",
        MesBcSupperFieldList: "/mes-code/mesBcPro/detail",
        AddPrinting: "/mes-code/mesBcPrint",
      },
      dictOptions: {
        filedType: [],
        barcodeBinary: [],
        barcodeSource: [],
        status: [],
      },
      /* 分页参数 */
      ipagination: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ["10", "20", "50"],
        showTotal: (total, range) => {
          return range[0] + "-" + range[1] + " 共" + total + "条";
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0,
      },
      selectedMainId: "",
    };
  },
  computed: {
    importExcelUrl: function () {
      return `${api.test}${this.url.importExcelUrl}`;
    },
    getWidth: function () {
      if (this.defColumns.length > 14) {
        return { width: "500px" };
      }
    },
    ...mapState({
      userInfo: (state) => state.user,
    }),

    tableScroll: function () {
      if (this.columns.length > 13) {
        return { x: this.columns.length * 150 - 450 };
      }
    },
  },

  created() {
    this.initColumns();
    this.setdefColumns();
  },

  methods: {
    setdefColumns() {
      if (this.columns.length > 13) {
        let arrLength = this.columns.length - 1;
        this.columns.forEach((item, index) => {
          item["width"] = 130;
        });
        this.columns[0]["width"] = "60px";
        this.columns[0]["fixed"] = "left";
        this.columns[1]["fixed"] = "left";
      }
    },
    // handleAlert: function () {
    //   let length=this.plainOptions.filter(item=>item.checked).length
    //   this.EnhanceJS=this.queryList
    //   if(this.mainId.length==length){
    //     this.$refs.modalForm.add();
    //     this.$refs.modalForm["getRuleCodeValue"]
    //       ? this.$refs.modalForm.getRuleCodeValue()
    //       : "";
    //     this.$refs.modalForm.title = "提示";
    //     this.$refs.modalForm.disableSubmit = false;
    //   }else{
    //     alert('请选择全部产品')
    //   }

    // },
    initColumns() {
      //权限过滤（列权限控制时打开，修改第二个参数为授权码前缀）
      //this.defColumns = colAuthFilter(this.defColumns,'testdemo:');

      var key = this.$route.name + ":colsettings";
      let colSettings = Vue.ls.get(key);
      if (colSettings == null || colSettings == undefined) {
        let allSettingColumns = [];
        this.defColumns.forEach(function (item, i, array) {
          allSettingColumns.push(item.dataIndex);
        });
        this.settingColumns = allSettingColumns;
        this.columns = this.defColumns;
      } else {
        this.settingColumns = colSettings;
        const cols = this.defColumns.filter((item) => {
          if (item.key == "rowIndex" || item.dataIndex == "action") {
            return true;
          }
          if (colSettings.includes(item.dataIndex)) {
            return true;
          }
          return false;
        });
        this.columns = cols;
      }
    },
    //列设置更改事件
    onColSettingsChange(checkedValues) {
      var key = this.$route.name + ":colsettings";
      Vue.ls.set(key, checkedValues, 7 * 24 * 60 * 60 * 1000);
      this.settingColumns = checkedValues;
      const cols = this.defColumns.filter((item) => {
        if (item.key == "rowIndex" || item.dataIndex == "action") {
          return true;
        }
        if (this.settingColumns.includes(item.dataIndex)) {
          return true;
        }
        return false;
      });
      this.columns = cols;
    },
    textPrink() {
      // document.getElementById('printIframe').contentWindow.print();
    },
    handleClick() {
      this.$refs.Child.doPrint3();
    },

    //高级查询方法
    handleSuperQuery(arg) {
      if (!arg) {
        this.superQueryParams = "";
        this.superQueryFlag = false;
      } else {
        this.superQueryFlag = true;
        this.superQueryParams = JSON.stringify(arg);
      }
      this.loadData();
    },
    // 获取查询条件
    getQueryParams() {
      let sqp = {};
      if (this.superQueryParams) {
        sqp["superQueryParams"] = encodeURI(this.superQueryParams);
      }
      var newData = {
        labelTemplateName: this.queryList.labelTemplateName,
        pageNo: this.ipagination.current,
        limit: this.ipagination.pageSize,
      };

      return filterObj(newData);
    },
    getQuery() {
      var newData = {
        // mcode: this.queryParam.mcode,
        barcodeProduceNo: this.changeData.barcodeProduceNo,
        barcodeType: 1,
      };
      return filterObj(newData);
    },

    clickThenSelect(record) {
      return {
        on: {
          click: () => {
            this.onSelectChange(record.id.split(","), [record]);
          },
        },
      };
    },
    onClearSelected() {
      this.selectedRowKeys = [];
      this.selectionRows = [];
      this.selectedMainId = "";
    },
    onSelectChange(selectedRowKeys, selectionRows) {
      this.selectedMainId = selectedRowKeys[0];
      this.selectedRowKeys = selectedRowKeys;
      this.selectionRows = selectionRows;
      this.EnhanceJS = this.dataSource.find(
        (item) => item.id == this.selectedMainId
      );
    },
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error("请设置url.list属性!");
        return;
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1;
      }
      getAction(this.url.list, paramsSelelist).then((res) => {
        if (res.code == 0) {
          this.queryParam = res.data.records;
        }
      });
      getAction(this.url.NoList, { barcodeType: "1" }).then((res) => {
        if (res.code == 0) {
          this.mes_filed_type = res.data;
          console.log(this.mes_filed_type);
        }
      });
      this.onClearSelected();
      var params = {
        labelTemplateNo: this.queryList.labelTemplateNo,
        pageNo: 1,
        limit: 10,
      };
      var paramsSelelist = { pageNo: "1", limit: "10" };
      this.loading = true;
      getAction(this.url.list, params).then((res) => {
        if (res.success) {
          this.dataSource = res.data.records;
        }
        if (res.code === 510) {
          this.$message.warning(res.msg);
        }
        this.loading = false;
      });
    },
    getChild(checkAll) {
      this.plainOptions = checkAll;
    },
    searchQuery() {
      this.loadData();
      var getQuery = this.getQuery(); //查询条件
      getAction(this.url.MesBcSupperFieldList, getQuery).then((res) => {
        if (res.success) {
          this.mainId = res.data;
        }
        if (res.code === 510) {
          this.$message.warning(res.msg);
        }
      });
    },

    // 选择生产工单，拉取数据
    QueryData(val) {
      this.queryList = val;
      let data = {
        labelTemplateNo: val.labelTemplateNo,
        pageNo: 1,
        limit: 10,
      };
      getAction(this.url.list, data).then((res) => {
        if (res.success) {
          this.dataSource = res.data.records;
          if (this.dataSource.length == 1) {
            this.selectedRowKeys = [this.dataSource[0].id];
            this.selectionRows = this.dataSource;
          }
        }
        if (res.code === 510) {
          this.$message.warning(res.msg);
        }
        this.loading = false;
      });
    },
    QueryList(data) {
      this.changeData = data;
      let obj = {
        barcodeType: 1,
        barcodeProduceNo: data.produceNo,
      };
      getAction(this.url.MesBcSupperFieldList, obj).then((res) => {
        if (res.success) {
          this.mainId = res.data;
          this.listLength = res.data.length;
        }
        if (res.code === 510) {
          this.$message.warning(res.msg);
        }
      });
    },

    // 过滤数据
    fiterData(data) {
      this.mes_filed_type = [];
      data.forEach((item) => {
        let list = {};
        list.id = item.id;
        list.productionno = item.productionno;
        list.planqty = item.planqty;
        list.mname = item.mname;
        list.mcode = item.mcode;
        this.mes_filed_type.push(list);
      });
    },
    showModal() {
      this.visible = true;
    },
    handleOk(e) {
      this.visible = false;
    },
    handleCancel(e) {
      this.visible = false;
    },

    // 弹出窗组件
    showDemoModal() {
      this.$refs.modalCompon.modalShow();
    },
    // 点击btn获取数据
    btnGetData(tableName, title) {
      getAction(`${this.url.getColumns}`, {
        tableName: tableName,
      }).then((res) => {
        if (res.code == 0) {
          this.queryInfo = res.data.columns;
          this.title = title;
          this.dictOptions = res.data.dictOptions;
          this.showDemoModal();
        } else {
          this.$message.warning(res.msg);
        }
      });
    },

    //筛选分组
    getGroupTag(arrList) {
      let arr = [];
      var map = {},
        dest = [];
      arrList.forEach((item, index) => {
        if (item.groupTag) {
          arr.push(item);
        }
      });
      for (var i = 0; i < arr.length; i++) {
        var ai = arr[i];
        if (!map[ai.groupTag]) {
          dest.push({
            groupTag: ai.groupTag,
            name: ai.groupName,
            data: [ai],
          });
          map[ai.groupTag] = ai;
        } else {
          for (var j = 0; j < dest.length; j++) {
            var dj = dest[j];
            if (dj.groupTag == ai.groupTag) {
              dj.data.push(ai);
              break;
            }
          }
        }
      }
      this.groupTag = dest;
    },
    showLinkButton(item, record) {
      let btn = new ButtonExpHandler(item.exp, record);
      return btn.show;
    },

    initCgEnhanceJs(enhanceJs) {
      //console.log("--onlineList-js增强",enhanceJs)
      if (enhanceJs) {
        let Obj = eval("(" + enhanceJs + ")");
        this.EnhanceJS = new Obj(getAction, postAction, deleteAction);
        this.cgButtonJsHandler("created");
      } else {
        this.EnhanceJS = "";
      }
    },
    initCgButtonList(btnList) {
      let linkArr = [];
      let buttonArr = [];
      if (btnList && btnList.length > 0) {
        for (let i = 0; i < btnList.length; i++) {
          let temp = btnList[i];
          if (temp.buttonStyle == "button") {
            buttonArr.push(temp);
          } else if (temp.buttonStyle == "link") {
            linkArr.push(temp);
          }
        }
      }
      this.cgButtonLinkList = [...linkArr];
      this.cgButtonList = [...buttonArr];
      console.log("链接增强", this.cgButtonLinkList);
    },
    cgButtonJsHandler(buttonCode) {
      if (this.EnhanceJS[buttonCode]) {
        this.EnhanceJS[buttonCode](this);
      }
    },
    cgButtonActionHandler(buttonCode) {
      //处理自定义button的 需要配置该button自定义sql
      if (!this.selectedRowKeys || this.selectedRowKeys.length == 0) {
        this.$message.warning("请先选中一条记录");
        return false;
      }
      if (this.selectedRowKeys.length > 1) {
        this.$message.warning("请只选中一条记录");
        return false;
      }
      let params = {
        formId: this.code,
        buttonCode: buttonCode,
        dataId: this.selectedRowKeys[0],
      };
      console.log("自定义按钮请求后台参数：", params);
      postAction(this.url.buttonAction, params).then((res) => {
        if (res.success) {
          this.loadData();
          this.$message.success("处理完成!");
        } else {
          this.$message.warning("处理失败!");
        }
      });
    },
    cgButtonLinkHandler(record, buttonCode, optType) {
      if (optType == "js") {
        if (this.EnhanceJS[buttonCode]) {
          this.EnhanceJS[buttonCode](this, record);
        }
      } else if (optType == "action") {
        let params = {
          formId: this.code,
          buttonCode: buttonCode,
          dataId: record.id,
        };
        console.log("自定义按钮link请求后台参数：", params);
        postAction(this.url.buttonAction, params).then((res) => {
          if (res.success) {
            this.loadData();
            this.$message.success("处理完成!");
          } else {
            this.$message.warning("处理失败!");
          }
        });
      }
    },
    // 打印
    handleAlert() {
      if (this.selectedRowKeys.length > 0) {
        if (this.NumberParinted) {
          let checked = this.plainOptions.filter((item) => item.checked);
          if (checked.length == this.mainId.length) {
            let data = this.getAddPrinting();
            postActionBasic(this.url.AddPrinting, data).then((res) => {
              if (res.code == 0) {
                var id = "produceId=" + checked[0].mesBcProduceId;
                var href = this.selectionRows[0].ureportAddress + "&" + id;
                this.$router.push({
                  path: `/layouts/IframePageRouter?=${href}`,
                });
                this.visible = false;
                this.$message.success("提交成功");
              } else {
                this.$message.warning(res.msg);
              }
            });
          } else {
            this.$message.warning("请选择全部条码");
          }
        } else {
          this.$message.warning("请输入打印份数");
        }
      } else {
        this.$message.warning("请选择打印模板");
      }
    },
    // 试打
    handleClick() {
      if (this.EnhanceJS) {
        if (this.NumberParinted) {
          let checked = this.plainOptions.filter((item) => item.checked);
          if (checked.length == 1) {
            var id = "bcIds=" + checked[0].id;
            console.log(this.selectionRows)
            var href = this.selectionRows[0].ureportAddress  + "&" + id;
            // var href="http://192.168.6.145/fx-platform/ureport/preview?_u=mysql-%E5%B0%8F%E6%A0%87%E7%AD%BE%E6%B5%8B%E8%AF%95.ureport.xml&"+ id
            this.$router.push({
              path: `/layouts/IframePageRouter?=${href}`,
            });
            this.visible = false;
          } else {
            this.$message.warning("请选择一个条码打印");
          }
        } else {
          this.$message.warning("请输入打印份数");
        }
      } else {
        this.$message.warning("请选择打印模板");
      }
    },
    // 补印
    myAddHtml() {
      if (this.EnhanceJS) {
        if (this.supplementParinted) {
          let checked = this.plainOptions.filter((item) => item.checked);
          let data = this.getAddPrinting();
          // postActionBasic(this.url.AddPrinting,data).then((res)=>{
          //   if(res.code==0){
          //     this.$message.success('提交成功');
          //   }else{
          //      this.$message.warning(res.msg);
          //   }
          let dataString = [];
          checked.forEach((item) => {
            dataString.push(item.id);
          });
          var id = "bcIds=" + dataString.toString();
          var href = this.selectionRows[0].ureportAddress  + "&" + id;
          // var href="http://192.168.6.145/fx-platform/ureport/preview?_u=mysql-%E5%B0%8F%E6%A0%87%E7%AD%BE%E6%B5%8B%E8%AF%95.ureport.xml&"+ id
          this.$router.push({
            path: `/layouts/IframePageRouter?=${href}`,
          });
          this.visible = false;
          // })
        } else {
          this.$message.warning("请输入补印份数");
        }
      } else {
        this.$message.warning("请选择打印模板");
      }
    },
    // 提交打印记录数据
    getAddPrinting() {
      console.log(this.selectionRows)
      let data = {
        name: this.userInfo.name, //打印人
        qty: this.PrintingNumber, //打印份数
        labelTemplateName: this.selectionRows[0].labelTemplateName, //标签模板名称
        labelTemplateNo: this.selectionRows[0].labelTemplateNo, //标签模板编号
        labelTemplateId:this.selectionRows[0].labelTemplateid,
        ruleId: this.changeData.barcodeRuleId, //规则id
        ruleName: this.changeData.barcodeRule, //规则名称
        beginBarcode: this.changeData.firstBarcode, //首码
        endBarcode: this.changeData.endBarcode, //尾码
        qty: this.listLength, //打印数量
        barcodeProduceNo:this.active,//条码生成编码，
      };
      return data;
    },
    getObjKeys() {
      [
        {
          dictCode: "mes-label-template-length",
          keysName: "labelTemplateLengthKeys",
        },
        { dictCode: "mes_label_type", keysName: "labelTypeKeys" },
        { dictCode: "mes_label_color", keysName: "labelColorKeys" },
        { dictCode: "mes-ribbons-type", keysName: "ribbonsTypeKeys" },
        { dictCode: "mes_printer_type", keysName: "printerTypeKeys" },
        { dictCode: "ba_yn", keysName: "containSnKeys" },
      ].forEach(({ dictCode, keysName }) => {
        ajaxGetDictItems(dictCode).then((res) => {
          const obj = {};
          if (res.success) {
            res.data.forEach((ele) => {
              obj[ele.value] = ele.text;
            });
          }
          this[keysName] = obj;
        });
      });
    },
  },
  watch: {
    NolistActive() {
      if (this.NolistActive == 0) {
        this.queryList = "";
      }
    },
  },
  mounted() {
    this.getObjKeys();
  },
};
</script>
<style scoped>
@import "~@assets/less/common.less";
</style>
